package org.me;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

//import org.codeandmagic.android.asmack_test.ServiceConnection;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.Roster.SubscriptionMode;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Authentication;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
import org.me.adapter.Adapter_Contact;
import org.me.utils.Koneksi;
import org.me.utils.PacketEventDispatcher;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;

public class ContactList extends Activity  {
	
	private PresenceSet sPresence;
	private RemoveUser rUser;
	private AddUser aUser;
    private ExpandableListView cList;
	XMPPConnection connection;
	Koneksi koneksi;
	Client client;
	private Adapter_Contact adapter;
	String tes;
	static Handler mHandler = new Handler();
	static Handler mHandler2 = new Handler();
	static Runnable Refresh;
	static ArrayList<String> temp;
	static ArrayList<ArrayList<String>> ex;
	ArrayList<String> groups;
//	ArrayList<ArrayList<String>> status;
	ArrayList<String> cont;
	ArrayList<String> cont1;
//	PacketListener presenceListener;
	String requestfrom;
	String toRoster;
	
//	private final ServiceConnection mConnection = new ServiceConnection() {
//
//		@Override
//		public void onServiceConnected(final ComponentName name, final IBinder service) {
//			mService = ((LocalBinder<MyService>) service).getService();
//			mBounded = true;
//			Log.d(TAG, "onServiceConnected");
//		}
//
//		@Override
//		public void onServiceDisconnected(final ComponentName name) {
//			mService = null;
//			mBounded = false;
//			Log.d(TAG, "onServiceDisconnected");
//		}
//	};

	public void onCreate(Bundle icicle) {
//		if (Koneksi.getInstance().getConnection().isConnected()) {
			super.onCreate(icicle);
	        setContentView(R.layout.contact_list);
	        connection = Koneksi.getInstance().getConnection();
	        cList = (ExpandableListView) this.findViewById(R.id.listContact);
	        
	        Typeface font = Typeface.createFromAsset(getAssets(), "fonts/tt0142m_.ttf");
	        
	        String name = StringUtils.parseName(Koneksi.getInstance().getConnection().getUser());
	        String address = StringUtils.parseBareAddress(Koneksi.getInstance().getConnection().getUser());
	        Roster ros = Koneksi.getInstance().getConnection().getRoster();
	        String pres = ros.getPresence(address).toString();

	        TextView profilestatus = (TextView) findViewById(R.id.profilestatus);
	        profilestatus.setTypeface(font);
	        
	        TextView profile = (TextView) findViewById(R.id.profile);
	        profile.setTypeface(font);
//	        profile.setText(name+" - "+pres);
	        profile.setText(name);
//	        profile.setOnClickListener(new OnClickListener() {
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					Intent myIntent = new Intent(v.getContext(), MyProfile.class);
//					startActivity(myIntent);
//				}
//			});
	        
//	        Refresh = new Runnable() {
//				@Override
//				public void run() {
					ArrayList<String> con = Koneksi.getInstance().getContact();
					ArrayList<String> gro = Koneksi.getInstance().getContactGroup();
					groups = Koneksi.getInstance().getAllGroup();
			        Set<String> s = new LinkedHashSet<String>(groups);
			        temp = new ArrayList<String>(s);
			        Collections.sort(temp);
			        
//			        System.out.println("##|temp.size(): "+temp.size());
//			        for (int i=0; i<temp.size(); i++) {
//			        	System.out.println("##|temp1: "+temp.get(i));
//					}
			        
					ex = new ArrayList<ArrayList<String>>();
					for (int i=0; i<temp.size(); i++) {
						ex.add(new ArrayList<String>());
					}
					for (int i=0; i<temp.size(); i++) {
						ex.get(i).addAll(Koneksi.getInstance().getContactOneGroup(temp.get(i)));
					}
					
//					System.out.println("##|contactonegroup: "+Koneksi.getInstance().getContactOneGroup("Friends"));
					
//					for (int j=0; j<ex.size(); j++) {
//						System.out.println("######|group: "+ex.get(j));
//						for (int k=0; k<ex.get(j).size(); k++) {
//							System.out.println("######|child: "+ex.get(j).get(k));
//						}
//					}
					
//					status = new ArrayList<ArrayList<String>>();
//					for (int i=0; i<temp.size(); i++) {
//						status.add(new ArrayList<String>());
//					}
//					for (int i=0; i<temp.size(); i++) {
//						status.get(i).addAll(Koneksi.getInstance().getStatus(temp.get(i)));
//					}
////					ArrayList<String> stat = Koneksi.getInstance().getStatus("Friends");
//					
//					for (int j=0; j<status.size(); j++) {
//						System.out.println("######|groupstatus: "+status.get(j));
//						for (int k=0; k<status.get(j).size(); k++) {
//							System.out.println("######|childstatus: "+status.get(j).get(k));
//						}
//					}
					
//					Koneksi.getInstance().getStatus();
//					ArrayList<String> gro1 = Koneksi.getInstance().getContactOneGroup("Friends");
//					System.out.println(gro[0]+"....."+gro[1]+"....."+gro[2]);
					adapter = new Adapter_Contact(getBaseContext(), temp, ex);
					cList.setAdapter(adapter);
//					adapter.notifyDataSetChanged();
//					cList.invalidateViews();
					
//					System.out.println("########|running...|#########");
//					mHandler.postDelayed(this, 1000);
//				}
//			};
//			mHandler.post(Refresh);
			
			cList.setOnChildClickListener(new OnChildClickListener()
	        {
	            @Override
	            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
	            {
	                Koneksi.getInstance().setChildPosition(childPosition);
	                Koneksi.getInstance().setGroupPosition(groupPosition);
	                groups = Koneksi.getInstance().getAllGroup();
	                Set<String> s = new LinkedHashSet<String>(groups);
	                temp = new ArrayList<String>(s);
	                Collections.sort(temp);
	                ArrayList<ArrayList<String>> exContact = new ArrayList<ArrayList<String>>();
	                
	        		for (int i=0; i<temp.size(); i++) {
	        			exContact.add(new ArrayList<String>());
	        		}
	        		for (int i=0; i<temp.size(); i++) {
	        			exContact.get(i).addAll(Koneksi.getInstance().getContactOneGroup(temp.get(i)));
	        		}
	        		
	        		ArrayList<String> contacts = Koneksi.getInstance().getContactUser();
	        		Roster roster = Koneksi.getInstance().getConnection().getRoster();
	            	System.out.println("123 "+roster.getEntry(contacts.get(0)).getName().toString());
	            	System.out.println("456 "+exContact.get(groupPosition).get(childPosition));
	            	
	            	for (int i=0; i<contacts.size(); i++) {
	            		String name = roster.getEntry(contacts.get(i)).getName();
	            		System.out.println("name= "+name);
	        			if (name.equalsIgnoreCase(exContact.get(groupPosition).get(childPosition))) {
	        				toRoster = contacts.get(i);
	        				System.out.println("789 "+contacts.get(i));
	        				int slashindex = toRoster.indexOf('/');
	        				if (slashindex>0) {
								toRoster = toRoster.substring(0, slashindex);
							}
	        				System.out.println(toRoster);
	        			}
	            	}
	            	
	            	System.out.println("CLtoRoster= "+toRoster);
	            	
	        		Intent myIntent = new Intent(v.getContext(), Client.class);
	        		myIntent.putExtra("userChat", toRoster);
	        		myIntent.putExtra("roster", true);
	        		startActivity(myIntent);
	                return false;
	            }
	        });
	        
	        cList.setOnGroupClickListener(new OnGroupClickListener()
	        {	            
	            @Override
	            public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2, long arg3)
	            {
	                return false;
	            }
	        });

	        
//		}
//		else if (!Koneksi.getInstance().isConnected()){
//			setContentView(R.layout.login);
//	        setTitle("Login");
//			Toast.makeText(this, "You must Login", Toast.LENGTH_LONG).show();
//		}
	        
	        Refresh = new Runnable() {
				@Override
				public void run() {
					cont1 = new ArrayList<String>();
					
					cont1 = Koneksi.getInstance().getAllGroup();
					Set<String> s1 = new LinkedHashSet<String>(cont1);
//					System.out.println("@@@@@@@|cont1s1 size: "+s1.size());
//					System.out.println("@@@@@@@|temp size: "+temp.size());
					if (s1.size() != temp.size()) {						
						temp.clear();
						temp = new ArrayList<String>(s1);
//						temp.addAll(cont1);
				        Collections.sort(temp);
					}
					
			        cont = new ArrayList<String>();
					for (int i=0; i<temp.size(); i++) {
						cont = Koneksi.getInstance().getContactOneGroup(temp.get(i));
//						System.out.println("@@@@@@@|cont size: "+cont.size());
//						System.out.println("@@@@@@@|ex size: "+ex.get(i).size());
						if (cont.size() != ex.get(i).size()) {
							System.out.println("satu");
							ex.get(i).clear();
							ex.get(i).addAll(cont);
						}
						else {
							for (int j=0; j<cont.size(); j++) {
								if (!cont.get(j).equalsIgnoreCase(ex.get(i).get(j))) {
									ex.get(i).clear();
									ex.get(i).addAll(cont);
								}
							}
						}
					}
					
		            adapter.addItem(temp, ex);
		            
		            adapter.notifyDataSetChanged();
			    	adapter.notifyDataSetInvalidated();
			    	cList.invalidateViews();
					
//			    	System.out.println("+++++++|post delay|++++++++");
			    	mHandler.postDelayed(Refresh, 2000);
				}
	        };
	        mHandler.post(Refresh);
	        
	        
        registerForContextMenu(cList);

        
//        PacketEventDispatcher.addListener(new org.me.utils.PacketListener() {
//			
//        	@Override
//			public void tgroupInvitationHandler(Message message) {
//				System.out.println("tgroupInvitationHandler= "+message.toXML());
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void rosterRequestHandler(Presence presence) {
//				System.out.println("rosterRequestHandler= "+presence.toXML());
//				// TODO Auto-generated method stub
//				Roster roster = connection.getRoster();
//            	requestfrom = (presence).getFrom();
//            	System.out.println("subscribe true");
//            	presence.setFrom(presence.getTo());
//            	presence.setTo(requestfrom);
//            	presence.setType(Presence.Type.subscribed);
//            	System.out.println("true1 "+presence.toXML());
//                connection.sendPacket(presence);
//                presence.setStatus("Online");
//                System.out.println("true2 "+presence.toXML());
//                connection.sendPacket(presence);
//                presence.setType(Presence.Type.subscribe);
//                System.out.println("true2 "+presence.toXML());
//                connection.sendPacket(presence);
//                
//                try {
//					roster.createEntry(requestfrom, StringUtils.parseName(requestfrom), new String[] {"Friends"});
//				} catch (XMPPException e) {
//					e.printStackTrace();
//				}
//                
//            	System.out.println("2 "+presence.getFrom()+"||||||||"+presence.getTo());
//            	System.out.println(roster.getEntries());
//            	System.out.println("3 "+StringUtils.parseName(presence.getFrom()));
//				
//			}
//			
//			@Override
//			public void presenceHandler(Presence presence) {
//				System.out.println("presenceHandler= "+presence.toXML());
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void mucMessageHandler(Message message) {
//				System.out.println("mucMessageHandler= "+message.toXML());
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void mucInvitationHandler(Message message) {
//				System.out.println("mucInvitationHandler= "+message.toXML());
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void messageHandler(Message message) {
//				System.out.println("messageHandler= "+message.toXML());
//				// TODO Auto-generated method stub
//				if (message.getBody() != null) {
//					Koneksi.getFrom().add(StringUtils.parseName(message.getFrom()));
//					Koneksi.getTo().add(StringUtils.parseName(message.getTo()));
//					Koneksi.getMess().add(StringUtils.parseName(message.getFrom())+": "+message.getBody());
//					System.out.println("body= "+message.getBody()+"||from= "+message.getFrom());
//				}
//				System.out.println(Koneksi.getMess());
//				System.out.println(Koneksi.getFrom());
//				System.out.println(Koneksi.getTo());
//			}
//		});
        
        
	}
    
//	public void dialog() {
//		AlertDialog.Builder b = new AlertDialog.Builder(this);
//    	b.setMessage("Add to your roster?")
//    	.setPositiveButton("Yes", null)
//    	.setNegativeButton("No", null);
//
//    	AlertDialog a = b.create();
//    	a.setTitle("Title");
//    	a.show();
//	}

	public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);

		ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
		int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
		int child = ExpandableListView.getPackedPositionChild(info.packedPosition);
		//Only create a context menu for child items
		if (type == 1) {
			//Array created earlier when we built the expandable list
			String page = ex.get(group).get(child);
			menu.setHeaderTitle(page);
			String[] menuItems = {"edit","delete"};
		    for (int i = 0; i<menuItems.length; i++) {
		      menu.add(Menu.NONE, i, i, menuItems[i]);
		    }
		}
	}
	
	public boolean onContextItemSelected(MenuItem menuItem) {
		final String server = StringUtils.parseServer(Koneksi.getInstance().getConnection().getUser());
		final Roster roster = Koneksi.getInstance().getConnection().getRoster();
		final ArrayList<String> contacts = Koneksi.getInstance().getContactUser();
		
		ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
		int groupPos = 0, childPos = 0;
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
		if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
			groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
			childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
		}  
		int menuItemIndex = menuItem.getItemId();
		String menuItemName = menuItem.toString();
		final String listItemName = ex.get(groupPos).get(childPos);
		final EditText editName = new EditText(this);
		editName.setSingleLine(true);
//		Spinner pilihGroup = new Spinner(this);

		if (menuItemIndex==0 && menuItemName.equalsIgnoreCase("edit")) {
			AlertDialog.Builder edit = new AlertDialog.Builder(this);
			
			System.out.println(editName.getText().toString());
			edit.setMessage("Edit Name "+listItemName+"?")
			.setView(editName)
			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					for (int i=0; i<contacts.size(); i++) {
						if (roster.getEntry(contacts.get(i)).getName().equalsIgnoreCase(listItemName)) {
							roster.getEntry(contacts.get(i)).setName(editName.getText().toString());
						}
					}
				}
			})
			.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					
				}
			});
			
			AlertDialog editDialog = edit.create();
			editDialog.setTitle("Edit");
			editDialog.show();
//			roster.getEntry(listItemName).setName(name);
		}
		else if (menuItemIndex==1 && menuItemName.equalsIgnoreCase("delete")) {
			AlertDialog.Builder del = new AlertDialog.Builder(this);
			del.setMessage(listItemName+" delete?")
			.setCancelable(false)
			.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					// TODO Auto-generated method stub
					System.out.println(listItemName);
					String delroster = null;
					for (int i=0; i<contacts.size(); i++) {
						if (roster.getEntry(contacts.get(i)).getName().equalsIgnoreCase(listItemName)) {
							delroster = contacts.get(i);
						}
					}
					
					try {
						roster.removeEntry(roster.getEntry(delroster));
					} catch (XMPPException e) {
						e.printStackTrace();
					}
				}
			})
			.setNegativeButton("No", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					System.out.println("Cancel");
				}
			});
			
			AlertDialog delUser = del.create();
			delUser.setTitle("Delete");
			delUser.show();
		}
//		else if (menuItemIndex==2 && menuItemName.equalsIgnoreCase("move")) {
//			ArrayList<String> groups = Koneksi.getInstance().getAllGroup();
//			ArrayList<String> conOneGroup;
//			String[] group_items = new String[groups.size()];
//			for (int i=0; i<group_items.length; i++) {
//				group_items[i] = groups.get(i);
//			}
//			
////			pilihGroup.setOnItemSelectedListener(this);
//			ArrayAdapter<String> adapter = new ArrayAdapter<String>(  
//			        this,
//			        android.R.layout.simple_spinner_item,
//			        group_items);
//			adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
//			pilihGroup.setAdapter(adapter);
//			
//			
//			String moveroster = null;
//			for (int i=0; i<contacts.size(); i++) {
//				if (roster.getEntry(contacts.get(i)).getName().equalsIgnoreCase(listItemName)) {
//					moveroster = contacts.get(i);
//				}
//			}
//			System.out.println(moveroster);
//			System.out.println(roster.getEntry(moveroster).getName());
//			
//			for (int i=0; i<groups.size(); i++) {
//				conOneGroup = Koneksi.getInstance().getContactOneGroup(groups.get(i));
//				for (int j=0; j<conOneGroup.size(); j++) {
//					if (conOneGroup.get(j).equalsIgnoreCase(listItemName)) {
//						System.out.println("groups= "+groups.get(i)+"|||||conOne= "+conOneGroup.get(j));
//					}
//				}
//			}
//			
//			AlertDialog.Builder move = new AlertDialog.Builder(this);
//			move.setMessage("Move "+listItemName+" to:")
//			.setView(pilihGroup)
//			.setPositiveButton("Move", new DialogInterface.OnClickListener() {
//				@Override
//				public void onClick(DialogInterface dialog, int which) {
//					// TODO Auto-generated method stub
//					
//				}
//			})
//			.setNegativeButton("Cancel", null);
//		}
		
		Toast.makeText(this, menuItemIndex+" "+String.format("Selected %s for item %s", menuItemName, listItemName), Toast.LENGTH_LONG).show();
		return true;
		  
	}
	
//	public void Refresh1() {
//		cont1 = new ArrayList<String>();
//		
//		cont1 = Koneksi.getInstance().getAllGroup();
//		Set<String> s1 = new LinkedHashSet<String>(cont1);
////		System.out.println("@@@@@@@|cont1s1 size: "+s1.size());
////		System.out.println("@@@@@@@|temp size: "+temp.size());
//		if (s1.size() != temp.size()) {						
//			temp.clear();
//			temp = new ArrayList<String>(s1);
////			temp.addAll(cont1);
//	        Collections.sort(temp);
//		}
//		
//        cont = new ArrayList<String>();
//		for (int i=0; i<temp.size(); i++) {
//			cont = Koneksi.getInstance().getContactOneGroup(temp.get(i));
////			System.out.println("@@@@@@@|cont size: "+cont.size());
////			System.out.println("@@@@@@@|ex size: "+ex.get(i).size());
//			if (cont.size() != ex.get(i).size()) {
//				ex.get(i).clear();
//				ex.get(i).addAll(cont);
//			}
//			else {
//				for (int j=0; j<cont.size(); j++) {
//					if (cont.get(j).equalsIgnoreCase(ex.get(i).get(j))) {
//						ex.get(i).clear();
//						ex.get(i).addAll(cont);
//					}
//				}
//			}
//		}
//		
//        adapter.addItem(temp, ex);
//        
//        adapter.notifyDataSetChanged();
//    	adapter.notifyDataSetInvalidated();
//    	cList.invalidateViews();
//	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		adapter.notifyDataSetChanged();
    	adapter.notifyDataSetInvalidated();
    	cList.invalidateViews();
		super.onResume();
	}


	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
//		Client.mHandler.removeCallbacks(Client.message_run);
//		ContactList.mHandler.removeCallbacks(ContactList.Refresh);
//		Koneksi.getInstance().getConnection().disconnect();
		Intent intent = new Intent(Intent.ACTION_MAIN);
	    intent.addCategory(Intent.CATEGORY_HOME);
	    startActivity(intent);

//		Intent myIntent = new Intent(this, Chat.class);
//		myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//		startActivity(myIntent);
	}


//	public void onChildClick(AdapterView<?> arg0, View view, int position, long id) {
////		Roster roster = connection.getRoster();
////		Collection<RosterEntry> entries = roster.getEntries();
////		for (RosterEntry entry : entries) {
////		    tes = entry.getUser();
////		}
//		Koneksi.getInstance().setPosition(position);
//		Intent myIntent = new Intent(view.getContext(), Client.class);
//		startActivityForResult(myIntent, 0);
//	}
	
	public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
//			case R.id.logout : 
//				ContactList.mHandler.removeCallbacks(ContactList.Refresh);
//				Koneksi.getInstance().getConnection().disconnect();
////				Koneksi.getInstance().destroy();
//				Intent chatIntent = new Intent(this, Chat.class);
//				chatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//	    		startActivity(chatIntent);
//	    		break;
//			case R.id.presence :
//				sPresence = new PresenceSet(this);
//				sPresence.show();
//				sPresence.setTitle("Set Presence");
//				break;
//			case R.id.rmvUser :
//				rUser = new RemoveUser(this);
//				rUser.show();
//				rUser.setTitle("Remove User");
//				break;
			case R.id.addUser :
				aUser = new AddUser(this);
				aUser.show();
				aUser.setTitle("Add User");
				break;
//			case R.id.viewProfile :
//				Intent profileIntent = new Intent(this, MyProfile.class);
//				startActivity(profileIntent);
			case R.id.mucList :
				Intent mucIntent = new Intent(this, MultiUserChat.class);
				startActivity(mucIntent);
			default :
				
		}
        return true;
    }

}